package com.easy.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easy.common.bean.SysPermission;
import com.easy.common.service.IPermissionService;
import com.easy.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("permission")
public class PermissionController {
    @Autowired
    IPermissionService permissionService;
    @PostMapping("/")
    public ResultData insert(@RequestBody SysPermission permission){
        SysPermission result=permissionService.insert(permission);
        return ResultData.success(result);
    }
    @PutMapping("/")
    public ResultData update(@RequestBody SysPermission permission){
        return ResultData.success(permissionService.update(permission));
    }
    @DeleteMapping("/{id}")
    public ResultData delete(@PathVariable Integer id){
        int result=permissionService.delete(id);
        if(result>=1){
            return ResultData.success();
        }else{
            return ResultData.fail();
        }
    }
    @GetMapping("/{id}")
    public ResultData getByID(@PathVariable Integer id){
        return ResultData.success(permissionService.getByID(id));
    }
    @GetMapping("/page")
    public ResultData getListByPage(IPage page,@RequestBody SysPermission permission){
        IPage<SysPermission> data=permissionService.getListByPage(page,permission);
        return ResultData.success(data);
    }
    @GetMapping("/list")
    public ResultData getList(SysPermission permission){
        List<SysPermission> data=permissionService.getList(permission);
        return ResultData.success(data);
    }
}
